#include "limbo/errc.h"
#include "limbo/ip/state.hpp"
#include "limbo/slip/state.hpp"
#include "limbo/stack.hpp"
#include "test-utils.h"

using namespace limbo;

using SLIP = slip::State<void>;
using IP = ip::State<SLIP>;
using MyStack = Stack<Layer<IP>, Layer<SLIP>>;

static_assert(!details::is_frameable<SLIP>, "slip is non-frameable");
static_assert(details::is_frameable<IP>, "ip is frameable");

TEST_CASE("empty SLIP frame is not upgraded to IP", "[ip+slip]") {
  unsigned char buff[] = {0xc0};
  auto buff_chunk = Chunk(buff, sizeof(buff));
  auto stack = MyStack();
  auto &state = stack.get<1, 0>();

  auto result = stack.recv(buff_chunk, nullptr);
  REQUIRE(result);
  CHECK(!result.demand());
  CHECK(result.state() == &state);
  CHECK(result.consumed() == buff_chunk);
  CHECK(state.get_parsed().payload.size() == 0);
}
